home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / vidDrvrH9550.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  17.5 KB  |  628 lines  |  [TEXT/MPS ]

  1. (*
  2.     vidDrvrH9550(cmd,parameters) -- Driver for the Hitachi 9550 videodisc player. The cmd parameter specifies the
  3.         function to be performed (p1 is the first parameter after cmd; p2 is the second, etc.):
  4.  
  5.                     Command        Function
  6.                     ---------        --------
  7.                     chapter            Return the chapter currently being displayed.
  8.                     control            Execute a series of control functions. Each addition parameter is a keyword to be
  9.                                         executed. If the keyword doesn't make sense here, pass it on to configureSPort.
  10.                                         The following keywords are understood by the video driver:
  11.                                                     Keyword                        Function
  12.                                                     --------                        --------
  13.                                                     init or reset                    Reset the player, configure the serial port (the baud rate is set to
  14.                                                                                         the highest available for the selected player).
  15.                                                     eject or reject                Eject the disc from the player.
  16.                                                     audioOff                        Turn off both audio channels.
  17.                                                     audio1On                        Turn on audio channel 1.
  18.                                                     audio2On                        Turn on audio channel 2.
  19.                                                     stereoOn                        Turn on both audio channels.
  20.                                                     pictureOn/pictureOff    Turn on/off the picture.
  21.                                                     framesOn/framesOff    Turn on/off the display of frame numbers.
  22.                                                     frameMode                    Set player to frame number mode.
  23.                                                     chapterMode                    Set player to chapter number mode.
  24.                                                     timeMode                        Set player to time mode.
  25.                                                     defaultComm                    Set default communications settings for this player.
  26.                     extended        Execute a function specific to the player. This player doesn't have any (yet).
  27.                     fps                Set the frames per second for the next playVideo command to p1, which can be a number or
  28.                                         one of "slowest", "slower", "slow", "normal", "fast", "faster", "fastest".
  29.                     frame            Return the current frame number.
  30.                     name            Return the long name of the player.
  31.                     play                Start a sequence playing, from p1 to p2, which are frame numbers, chapter numbers, or times,
  32.                                         depending upon the mode.
  33.                     scan                Scan forward or backward, depending upong whether p1 is "forward" or "backward".
  34.                     search            Search to frame, chapter, or time p1.
  35.                     sendCmd        Send command p1 to the player and wait for an acknowlege.
  36.                     speeds            Return the frames per second speeds allowed with this player.
  37.                     status            Return the status of the play, which is a comma-separated list containing:
  38.                                                         Keyword                                            Meaning
  39.                                                         --------                                            --------
  40.                                                         doorOpen or park or still or play        State of player.
  41.                                                         CLV or CAV                                        Type of disc.
  42.                                                         disc12inch or disc8inch                        Size of disc being played.
  43.                                                         side1 or side2                                    Side of disc being played.
  44.                     step                Step p1 frames forward (or backward if it's negative), and do it p2 times.
  45.                     time                Return the time of the frame currently being displayed, in 1/60ths of a second since the start
  46.                                         of the disc.
  47.                     version            Return the version of this player driver.
  48.  
  49.     To compile and link this file using Macintosh Programmer's Workshop,
  50.  
  51.         pascal -w vidDrvrH9550.p
  52.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=8034 -sn Main=vidDrvrH9550 ∂
  53.             vidDrvrH9550.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
  54.  
  55.     Copyright © 1988 Apple Computer, Inc.
  56.  
  57.     2/88 - Initial coding by Harry R. Chesley.
  58. *)
  59.  
  60. {$R-}
  61.  
  62. {$S vidDrvrH9550 }     { Segment name must be the same as the command name. }
  63.  
  64. unit DummyUnit;
  65.  
  66. interface
  67.  
  68. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  69.  
  70. procedure EntryPoint(paramPtr: XCmdPtr);
  71.     
  72. implementation
  73.  
  74. type
  75.  
  76. Str31 = String[31];
  77.  
  78. procedure vidDrvrH9550(paramPtr: XCmdPtr); forward;
  79.  
  80. procedure EntryPoint(paramPtr: XCmdPtr);
  81.  
  82.     begin
  83.         vidDrvrH9550(paramPtr);
  84.     end;
  85.  
  86. procedure vidDrvrH9550(paramPtr: XCmdPtr);
  87.  
  88.     type videoModes = (frameMode,chapterMode,timeMode);
  89.  
  90.     var returnValue: str255;
  91.         pCount: integer;
  92.         p1, p2: str255;
  93.         str: str255;
  94.         i: integer;
  95.         oneCharString: String[1];
  96.         theMode: videoModes;
  97.  
  98.     {$I XCmdGlue.inc}
  99.  
  100.     procedure Fail(errMsg: Str255); { set theResult and quit }
  101.         begin
  102.             paramPtr^.returnValue := PasToZero(errMsg);
  103.             exit(vidDrvrH9550);
  104.         end;
  105.  
  106.     {$I VideoUtil.inc}
  107.  
  108.     procedure sendCmd(theCommand, optParm: str255);
  109.         { Send a command to the player, waiting for the ack. Normally, the ack is
  110.             the command sent with the top bit set. If optParm is present, that value
  111.             is used instead. }
  112.  
  113.         var echoBack: str255;
  114.  
  115.         begin
  116.             SendCardMessage(Concat('sendSPort "',theCommand,'"'));
  117.             if optParm = '' then
  118.                 begin
  119.                     echoBack := Copy(theCommand,1,1);
  120.                     echoBack[1] := chr(ord(echoBack[1])+128);
  121.                 end
  122.             else echoBack := optParm;
  123.             EvalAndDispose(Concat('RecvUpTo("',echoBack,'",600,empty)'));
  124.         end;
  125.  
  126.     function chapter: str255;
  127.         { Return the current chapter number. }
  128.  
  129.         var str: str255;
  130.             endTick: longInt;
  131.             charCount: longInt;
  132.  
  133.         begin
  134.             { Ask for the chapter number in binary. }
  135.             sendCmd('l','l');
  136.     
  137.             { Wait for the number or time out. }
  138.             endTick := TickCount+120;
  139.             repeat charCount := StrToLong(EvalStr('charsAvailable()'));
  140.             until (charCount >= 1) or (TickCount > endTick);
  141.     
  142.             { If we got the number... }
  143.             if charCount >= 1 then
  144.                 begin
  145.                     { str := character one. }
  146.                     str := EvalStr('recvChars(1)');
  147.                     if length(str) = 0 then
  148.                         begin
  149.                             str[0] := chr(1); str[1] := chr(0);
  150.                         end;
  151.                     { Compute the chapter number. }
  152.                     chapter := LongToStr(BitAnd(ord(str[1]),255));
  153.                 end
  154.             else chapter := 'noAnswer';
  155.         end;
  156.  
  157.     procedure search(var toFrame: str255; blankSearch: boolean; mode: videoModes);
  158.         { Search to the specified frame, blanking if appropriate. }
  159.  
  160.         begin
  161.             if blankSearch then sendCmd('~','');
  162.             oneCharString[1] := chr(176);
  163.             if mode = chapterMode then sendCmd(Concat('+,',toFrame,'A'),oneCharString)
  164.             else sendCmd(Concat('+:',toFrame,'A'),oneCharString);
  165.             if blankSearch then sendCmd('n','');
  166.         end;
  167.  
  168.     procedure stop;
  169.         { Stop the player. }
  170.  
  171.         begin
  172.             sendCmd('$','');
  173.         end;
  174.  
  175.     procedure control(var keywd: str255);
  176.         { Handle a control command. }
  177.  
  178.         type
  179.             audioModes = (off,oneOn,twoOn,stereo);
  180.  
  181.         var numberOfParms: integer;
  182.             i: integer;
  183.             parm: str255;
  184.  
  185.         procedure ejectPlayer;
  186.             { Eject the disc. }
  187.     
  188.             begin
  189.                 { Send the appropriate eject command. }
  190.                 sendCmd('/','');
  191.             end;
  192.     
  193.         procedure audio(onOff: audioModes);
  194.             { Set the audio mode. }
  195.     
  196.             begin
  197.                 { Send the appropriate audio channel command. }
  198.                 case onOff of
  199.                     off:
  200.                         begin
  201.                             sendCmd('I','');
  202.                             sendCmd('K','');
  203.                         end;
  204.                     oneOn:
  205.                         begin
  206.                             sendCmd('H','');
  207.                             sendCmd('K','');
  208.                         end;
  209.                     twoOn:
  210.                         begin
  211.                             sendCmd('I','');
  212.                             sendCmd('J','');
  213.                         end;
  214.                     stereo:
  215.                         begin
  216.                             sendCmd('H','');
  217.                             sendCmd('J','');
  218.                         end;
  219.                     end;
  220.             end;
  221.     
  222.         procedure picture(onOff: boolean);
  223.             { Turn the picture on or off. }
  224.     
  225.             begin
  226.                 { Send the appropriate picture command. }
  227.                 if onOff then sendCmd('n','')
  228.                 else sendCmd('~','');
  229.             end;
  230.  
  231.         procedure frames(onOff: boolean);
  232.             { Turn the frame number display on or off. }
  233.  
  234.             var str: str255;
  235.                 inChapterMode: boolean;
  236.  
  237.             begin
  238.                 { Figure out if we're in chapter mode or not. }
  239.                 GetStrGlobal('videoMode',str);
  240.                 inChapterMode := StringEqual(str,'chapterMode');
  241.  
  242.                 { Send the appropriate frame display command. }
  243.                 if onOff then
  244.                     begin
  245.                         sendCmd('L','');
  246.                         if inChapterMode then sendCmd('N','');
  247.                     end
  248.                 else
  249.                     begin
  250.                         sendCmd('M','');
  251.                         sendCmd('O','');
  252.                     end;
  253.             end;
  254.  
  255.         procedure defaultComm;
  256.             { Set the default communications settings. }
  257.  
  258.             begin
  259.                 { Set the port configuration. }
  260.                 SendCardMessage('configureSPort baud9600,echoOff,editOff,linefeedOff,stripOff');
  261.             end;
  262.  
  263.         procedure setMode(theMode: str255);
  264.             { Set the frame/chapter/time mode. }
  265.  
  266.             begin
  267.                 SetStrGlobal('videoMode',theMode)
  268.             end;
  269.  
  270.         procedure initPlayer;
  271.             { Initialize the player. }
  272.  
  273.             var str: str255;
  274.  
  275.             begin
  276.                 { Empty out the globals. }
  277.                 SetStrGlobal('videoMode','');
  278.                 SetStrGlobal('blankNextVideo','');
  279.                 SetStrGlobal('videoSpeed','');
  280.     
  281.                 { Send the reset command for this player. }
  282.                 sendCmd('h','');
  283.                 EvalAndDispose('recvUpTo(empty,0,empty)');
  284.                 SendCardMessage('sendSPort "%"');
  285.                 EvalAndDispose('recvUpTo(numToChar(charToNum("%")+128),1200,empty)');
  286.  
  287.                 { Force it to stop. }
  288.                 stop;
  289.  
  290.                 { Reset the player to known defaults. }
  291.                 setMode('');
  292.                 audio(stereo);
  293.                 frames(false);
  294.                 picture(true);
  295.             end;
  296.     
  297.         begin
  298.             if StringEqual(keywd,'init') or StringEqual(keywd,'reset') then initPlayer
  299.             else if StringEqual(keywd,'eject') or StringEqual(keywd,'reject') then ejectPlayer
  300.             else if StringEqual(keywd,'audioOff') then audio(off)
  301.             else if StringEqual(keywd,'audio1On') then audio(oneOn)
  302.             else if StringEqual(keywd,'audio2On') then audio(twoOn)
  303.             else if StringEqual(keywd,'stereoOn') then audio(stereo)
  304.             else if StringEqual(keywd,'pictureOn') then picture(true)
  305.             else if StringEqual(keywd,'pictureOff') then picture(false)
  306.             else if StringEqual(keywd,'framesOn') then frames(true)
  307.             else if StringEqual(keywd,'framesOff') then frames(false)
  308.             else if StringEqual(keywd,'defaultComm') then defaultComm
  309.             else if StringEqual(keywd,'frameMode') then setMode('')
  310.             else if StringEqual(keywd,'chapterMode') then setMode('chapterMode')
  311.             else if StringEqual(keywd,'timeMode') then setMode('timeMode')
  312.             else SendCardMessage(Concat('configureSPort ',keywd));
  313.         end;
  314.  
  315.     function extended(var keywd: str255): str255;
  316.         { Execute an extended command or function. }
  317.  
  318.         begin
  319.             { No extended command for this player. }
  320.         end;
  321.  
  322.     procedure fps(var fpsKeywd: str255);
  323.         { Set the frames per second. }
  324.  
  325.         var speed: str255;
  326.  
  327.         begin
  328.             speed := '';
  329.  
  330.             { Default speed settings are fine, except: }
  331.             if StringEqual(fpsKeyWd,'fast') then speed := '90'
  332.             else if StringEqual(fpsKeyWd,'fastest') then speed := '90';
  333.  
  334.             { Set it. }
  335.             if speed <> '' then SetStrGlobal('videoSpeed',speed);
  336.         end;
  337.  
  338.     function frame: str255;
  339.         { Return the current frame number. }
  340.  
  341.         var str, str2: str255;
  342.             endTick: longInt;
  343.             charCount: longInt;
  344.  
  345.         begin
  346.             { Ask for the frame number in binary. }
  347.             sendCmd('k','k');
  348.     
  349.             { Wait for the number or time out. }
  350.             endTick := TickCount+120;
  351.             repeat charCount := StrToLong(EvalStr('charsAvailable()'));
  352.             until (charCount >= 2) or (TickCount > endTick);
  353.     
  354.             { If we got the number... }
  355.             if charCount >= 2 then
  356.                 begin
  357.                     { str := character one. }
  358.                     str := EvalStr('recvChars(1)');
  359.                     if length(str) = 0 then
  360.                         begin
  361.                             str[0] := chr(1); str[1] := chr(0);
  362.                         end;
  363.                     { str2 := character two. }
  364.                     str2 := EvalStr('recvChars(1)');
  365.                     if length(str2) = 0 then
  366.                         begin
  367.                             str2[0] := chr(1); str2[1] := chr(0);
  368.                         end;
  369.                     { Compute the frame number. }
  370.                     frame := LongToStr(BitOr(BitShift(ord(str[1]),8),ord(str2[1])))
  371.                 end
  372.             else frame := 'noAnswer';
  373.         end;
  374.  
  375.     function name: str255;
  376.         { Return the long name of the player. }
  377.  
  378.         begin
  379.             name := 'Hitachi 9550';
  380.         end;
  381.  
  382.     procedure play(var firstFrame,lastFrame,speed: str255; blankSearch: boolean; mode: videoModes);
  383.         { Play the segment. }
  384.  
  385.         var lastFrameNum: longInt;
  386.             startHere: boolean;
  387.             playToLast: boolean;
  388.             fpsNum: longInt;
  389.             str: str255;
  390.             rev: boolean;
  391.  
  392.         begin
  393.             { Figure out if we're playing to special (non-numeric markers). }
  394.             startHere := StringEqual(firstFrame,'here');
  395.             playToLast := StringEqual(lastFrame,'lastFrame');
  396.             if playToLast then
  397.                 begin
  398.                     if mode = chapterMode then
  399.                         begin
  400.                             lastFrame := '99';
  401.                             lastFrameNum := 99;
  402.                         end
  403.                     else
  404.                         begin
  405.                             lastFrame := '54000';
  406.                             lastFrameNum := 54000;
  407.                         end;
  408.                 end
  409.             else lastFrameNum := StrToLong(lastFrame);
  410.             fpsNum := StrToLong(speed);
  411.  
  412.             { Figure out whether we're playing forward or reverse. }
  413.             rev := (not playToLast) and
  414.                         (((not startHere) and (lastFrameNum < StrToLong(firstFrame))) or (lastFrameNum = 0));
  415.  
  416.             { Go to the first frame. }
  417.             if not startHere then search(firstFrame,blankSearch,mode);
  418.             { Play it. }
  419.             if fpsNum = 30 then
  420.                 begin
  421.                     if playToLast then sendCmd('%','')
  422.                     else if lastFrameNum = 0 then sendCmd('B','')
  423.                     else if mode = chapterMode then sendCmd(Concat('+,t$',LongToStr(lastFrameNum-1),'A'),'A')
  424.                     else sendCmd(Concat('+:t$',lastFrame,'A'),'A');
  425.                 end
  426.             else if fpsNum > 30 then
  427.                 begin
  428.                     if playToLast then sendCmd('!','')
  429.                     else if lastFrameNum = 0 then sendCmd('&','')
  430.                     else if mode = chapterMode then sendCmd('!','')
  431.                     else sendCmd(Concat('+!:t$',lastFrame,'A'),'A')
  432.                 end
  433.             else
  434.                 begin
  435.                     if rev then str := 'E'
  436.                     else str := 'D';
  437.                     if fpsNum = 15 then str := Concat(str,'2')
  438.                     else if fpsNum = 10 then str := Concat(str,'3')
  439.                     else if fpsNum = 3 then str := Concat(str,'10')
  440.                     else str := Concat(str,'30');
  441.                     if playToLast or (mode = chapterMode) or (lastFrameNum = 0) then sendCmd(Concat(str,'A'),'A')
  442.                     else sendCmd(Concat(str,'t$',lastFrame,'A'),'A');
  443.                 end;
  444.         end;
  445.  
  446.     function scan(scanForward: boolean): str255;
  447.         { Scan forward (if scanForward is true) or backward. }
  448.  
  449.         begin
  450.             if scanForward then
  451.                 begin
  452.                     EvalAndDispose('recvUpTo(empty,0,empty)');
  453.                     SendCardMessage('sendSPort quote');
  454.                     EvalAndDispose('recvUpTo(numToChar(charToNum(quote)+128),600,empty)');
  455.                 end
  456.             else sendCmd('''','');
  457.             scan := '';
  458.         end;
  459.  
  460.     procedure step(goForward: boolean);
  461.         { Step one frame forward (if goForward is true) or backward. }
  462.  
  463.         begin
  464.             if goForward then SendCmd('$','')
  465.             else SendCmd(')','');
  466.         end;
  467.  
  468.     function speeds: str255;
  469.         { Return the valid speed for this player. }
  470.  
  471.         begin
  472.             speeds := '1,3,10,15,30,90';
  473.         end;
  474.  
  475.     function status: str255;
  476.         { Return the current player status. }
  477.  
  478.         var str: str255;
  479.             theResult: str255;
  480.             endTick: longInt;
  481.             charCount: longInt;
  482.  
  483.         begin
  484.             { Ask for the play status. }
  485.             sendCmd('i','i');
  486.     
  487.             { Wait for the number or time out. }
  488.             endTick := TickCount+120;
  489.             repeat charCount := StrToLong(EvalStr('charsAvailable()'));
  490.             until (charCount >= 1) or (TickCount > endTick);
  491.     
  492.             theResult := 'noAnswer';
  493.  
  494.             { If we got the status... }
  495.             if charCount >= 1 then
  496.                 begin
  497.                     { str := character one. }
  498.                     str := EvalStr('recvChars(1)');
  499.                     if length(str) = 0 then
  500.                         begin
  501.                             str[0] := chr(1); str[1] := chr(0);
  502.                         end
  503.                     else str[1] := chr(BitAnd(ord(str[1]),127));
  504.                     if str[1] in ['*','C','$',')','u'] then theResult := 'still'
  505.                     else if str[1] = '/' then
  506.                         begin
  507.                             status := 'park';
  508.                             exit(status);
  509.                         end
  510.                     else theResult := 'play';
  511.                     
  512.                     { Ask for the disc info. }
  513.                     sendCmd('w','w');
  514.             
  515.                     { Wait for the number or time out. }
  516.                     endTick := TickCount+120;
  517.                     repeat charCount := StrToLong(EvalStr('charsAvailable()'));
  518.                     until (charCount >= 1) or (TickCount > endTick);
  519.                     
  520.                     { If we got the status... }
  521.                     if charCount >= 1 then
  522.                         begin
  523.                             { str := character one. }
  524.                             str := EvalStr('recvChars(1)');
  525.                             if length(str) = 0 then
  526.                                 begin
  527.                                     str[0] := chr(1); str[1] := chr(0);
  528.                                 end;
  529.                             if BitAnd(ord(str[1]),8) <> 0 then theResult := Concat(theResult,',,disc8inch')
  530.                             else theResult := Concat(theResult,',,disc12inch');
  531.                             if BitAnd(ord(str[1]),4) <> 0 then theResult := Concat(theResult,',side2')
  532.                             else theResult := Concat(theResult,',side1');
  533.                         end;
  534.                 end
  535.             else theResult := 'noAnswer';
  536.  
  537.             status := theResult;
  538.         end;
  539.  
  540.     function time: str255;
  541.         { Return the time for the current frame. }
  542.  
  543.         begin
  544.             time := 'notImplemented';
  545.         end;
  546.  
  547.     function version: str255;
  548.         { Return the version of this player driver. }
  549.  
  550.         begin
  551.             version := 'H9550 1.0';
  552.         end;
  553.  
  554.     begin
  555.         pCount := paramPtr^.paramCount;
  556.  
  557.         if pCount <= 0 then Fail('parameter count is not > 0');
  558.  
  559.         if pCount > 1 then GetStrParm(2,p1)
  560.         else p1 := '';
  561.         if pCount > 2 then GetStrParm(3,p2)
  562.         else p2 := '';
  563.  
  564.         oneCharString := 'x';
  565.  
  566.         GetStrParm(1,str);
  567.  
  568.         returnValue := '';
  569.  
  570.         if StringEqual(str,'chapter') then returnValue := chapter
  571.         else if StringEqual(str,'control') then
  572.             begin
  573.                 for i := 2 to pCount do
  574.                     begin
  575.                         GetStrParm(i,str);
  576.                         control(str);
  577.                     end;
  578.             end
  579.         else if StringEqual(str,'extended') then returnValue := extended(p1)
  580.         else if StringEqual(str,'fps') then fps(p1)
  581.         else if StringEqual(str,'frame') then returnValue := frame
  582.         else if StringEqual(str,'name') then returnValue := name
  583.         else if StringEqual(str,'play') then
  584.             begin
  585.                 GetStrGlobal('videoMode',str);
  586.                 if StringEqual(str,'chapterMode') then theMode := chapterMode
  587.                 else if StringEqual(str,'timeMode') then theMode := timeMode
  588.                 else theMode := frameMode;
  589.                 GetStrGlobal('blankNextVideo',str);
  590.                 if str = '' then
  591.                     begin
  592.                         GetStrGlobal('videoSpeed',str);
  593.                         play(p1,p2,str,false,theMode);
  594.                     end
  595.                 else
  596.                     begin
  597.                         GetStrGlobal('videoSpeed',str);
  598.                         play(p1,p2,str,false,theMode);
  599.                     end;
  600.             end
  601.         else if StringEqual(str,'scan') then
  602.             begin
  603.                 if length(p1) < 1 then returnValue := scan(true)
  604.                 else returnValue := scan(not ((p1[1] = 'b') or (p1[1] = 'B')));
  605.             end
  606.         else if StringEqual(str,'search') then
  607.             begin
  608.                 GetStrGlobal('videoMode',str);
  609.                 if StringEqual(str,'chapterMode') then theMode := chapterMode
  610.                 else if StringEqual(str,'timeMode') then theMode := timeMode
  611.                 else theMode := frameMode;
  612.                 GetStrGlobal('blankNextVideo',str);
  613.                 search(p1,str <> '',theMode);
  614.             end
  615.         else if StringEqual(str,'sendCmd') then sendCmd(p1,p2)
  616.         else if StringEqual(str,'step') then step(p1 = '1')
  617.         else if StringEqual(str,'speeds') then returnValue := speeds
  618.         else if StringEqual(str,'status') then returnValue := status
  619.         else if StringEqual(str,'stop') then stop
  620.         else if StringEqual(str,'time') then returnValue := time
  621.         else if StringEqual(str,'version') then returnValue := version;
  622.  
  623.         { Return the result (if any). }
  624.         paramPtr^.returnValue := PasToZero(returnValue)
  625.     end;
  626.  
  627. end.
  628.